home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / dev / src / wangisrc.lha / wangi / z / fakepoint / fakepoint.c < prev    next >
C/C++ Source or Header  |  1996-06-20  |  9KB  |  418 lines

  1. /* 
  2.  
  3. PKTShovel V1.1 freely distributable from the Plot Hatching Factory. 
  4.  
  5. Written my Mat 'Fingers' Bettinson and 10 jugs of coffee. 
  6.  
  7. Set the script flag on this file and copy into rexx: make sure your path is
  8. also set up to rexx: too... Then you just have to type PKTshovel rather than
  9. the rx etc... 
  10.  
  11. The systemname specifies a system in the config file. The config file
  12. specifies the paths and addresses to be shoveled etc. 
  13.  
  14. This program handles file attaches and everything else in the flowfile.
  15. Recognises what has to be deleted and not deleted. Datestamps packets as
  16. they are moved in 8 digit hex form. netmail with .PKT and Echo mail with the
  17. day and session stamp ie TH2, WE0 etc... 
  18.  
  19. Flowfiles and packets are deleted after copying. No checking is performed as
  20. there is no reason why a copy should fail. It's down to your config. The
  21. script works as I've tested it. Don't be paranoid now! :-) 
  22.  
  23. The Quiet switch turns off the copying and deleting output to the stdio.
  24.  
  25. The after-session script is configured in the config file again... It is
  26. simply executed so you MUST set the script flag or it WILL NOT WORK. I
  27. didn't execute it as it may be a DOS or Arexx script so I left it up to you.
  28.  
  29. Usage: [Rx] PKTShovel <systemname> [QUIET]
  30.  
  31. */
  32.  
  33. #include "gst.c"
  34.  
  35. #define DEF_PATH   "MAIL:Fake"
  36. #define DEF_SYSTEM ""
  37. #define DEF_GUI    TRUE
  38. #define MXSL       80
  39.  
  40. struct NodeSystem
  41. {
  42.     char *ns_Node;
  43.     List  ns_AKAs;
  44.     char *ns_PointInbound;
  45.     char *ns_PointOutbound;
  46.     char *ns_BossInbound;
  47.     char *ns_BossOutbound;
  48.     char *ns_Aftersession;
  49. };
  50.  
  51. struct IntuitionBase *IntuitionBase = NULL;
  52. struct Library *IconBase = NULL;
  53. extern struct ExecBase *SysBase;
  54.  
  55. int OpenLibs(void);
  56. void CloseLibs(void);
  57. struct NodeSystem *ReadNS(STRPTR);
  58. void FreeNS(struct NodeSystem*);
  59.  
  60. /* main */
  61. int main(int argc, char **argv)
  62. {
  63.     int  ret              = RETURN_OK;
  64.     char cfg_Path[MXSL]   = DEF_PATH;
  65.     char cfg_System[MXSL] = DEF_SYSTEM;
  66.     BOOL cfg_Gui          = DEF_GUI;
  67.     
  68.     /* Open all libraries */
  69.     if( OpenLibs() )
  70.     {    
  71.         /* Get tooltypes */
  72.         if (argc ? FALSE : TRUE)
  73.         {
  74.             /* Workbench */
  75.             BPTR oldcd;
  76.             struct DiskObject *dobj;
  77.             struct WBStartup *wbs;
  78.             #define PROGNAME wbs->sm_ArgList->wa_Name
  79.             #define PDIRLOCK wbs->sm_ArgList->wa_Lock
  80.             
  81.             wbs = (struct WBStartup *)argv;
  82.             oldcd = CurrentDir(PDIRLOCK);
  83.             if( dobj = GetDiskObject(PROGNAME) )
  84.             {
  85.                 STRPTR s;
  86.                 if( s = FindToolType(dobj->do_ToolTypes, "NOGUI") )
  87.                     cfg_Gui = FALSE;
  88.                 if( s = FindToolType(dobj->do_ToolTypes, "CONFIGPATH") )
  89.                 {
  90.                     strncpy(cfg_Path, s, MXSL);
  91.                     cfg_Path[MXSL-1] = NULL;
  92.                 }
  93.                 if( s = FindToolType(dobj->do_ToolTypes, "SYSTEM") )
  94.                 {
  95.                     strncpy(cfg_System, s, MXSL);
  96.                     cfg_System[MXSL-1] = NULL;
  97.                 }
  98.                 FreeDiskObject(dobj);
  99.             }
  100.             CurrentDir(oldcd);
  101.         } else
  102.         {
  103.             /* Shell */
  104.             struct RDArgs *rdargs;
  105.             #define OPT_SYSTEM     0
  106.             #define OPT_NOGUI      1
  107.             #define OPT_CONFIGPATH 2
  108.             #define TEMPLATE "SYSTEM,NOGUI/S,CONFIGPATH/K"
  109.             STRPTR args[3] = {0, 0, 0};
  110.             
  111.             if( rdargs = ReadArgs(TEMPLATE, (LONG *)&args, NULL) )
  112.             {
  113.                 if( args[OPT_SYSTEM] )
  114.                 {
  115.                     strncpy(cfg_System, args[OPT_SYSTEM], MXSL);
  116.                     cfg_System[MXSL-1] = NULL;
  117.                 }
  118.                 if( args[OPT_NOGUI] )
  119.                     cfg_Gui = FALSE;
  120.                 if( args[OPT_CONFIGPATH] )
  121.                 {
  122.                     strncpy(cfg_Path, args[OPT_CONFIGPATH], MXSL);
  123.                     cfg_Path[MXSL-1] = NULL;
  124.                 }
  125.                 FreeArgs(rdargs);    
  126.             }
  127.         }
  128.         Printf("Config path - \"%s\"\n", cfg_Path);
  129.         if( *cfg_System )
  130.         {
  131.             /* Act as a mailer */
  132.             BPTR oldcd, cd;
  133.             
  134.             Printf("Mailer mode - \"%s\"\n", cfg_System);
  135.             if( cfg_Gui )
  136.                 Printf("GUI active\n");
  137.             else
  138.                 Printf("No GUI\n");
  139.             
  140.             if( cd = Lock(cfg_Path, ACCESS_READ) )
  141.             {
  142.                 oldcd = CurrentDir(cd);
  143.                 CurrentDir(oldcd);
  144.                 UnLock(cd);
  145.             } else
  146.                 Printf("\"%s\" - invalid directory\n", cfg_Path);
  147.         } else
  148.         {
  149.             /* Preference editor mode */
  150.             Printf("Prefs mode\n");
  151.         }
  152.         CloseLibs();
  153.     }
  154.     return( ret );
  155. }
  156.  
  157.  
  158. int OpenLibs(void)
  159. {
  160.     return( (SysBase->LibNode.lib_Version >= 37) &&
  161.             (DOSBase->dl_lib.lib_Version >= 37) &&
  162.             (IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37)) &&
  163.             (IconBase = OpenLibrary("icon.library", 37)) );
  164. }
  165.  
  166. void CloseLibs(void)
  167. {
  168.     if( IconBase )
  169.         CloseLibrary(IconBase);
  170.     if( IntuitionBase )
  171.         CloseLibrary((struct Library *)IntuitionBase);
  172. }
  173.  
  174.  
  175. struct NodeSystem *ReadNS(STRPTR fname)
  176. {
  177.     BPTR f;
  178.     struct NodeSystem *ns = NULL;
  179.  
  180.     if( f = Open(fname, MODE_READ) )
  181.     {
  182.     }
  183.     return( ns );
  184. }
  185.  
  186. /*
  187.  
  188.  
  189. ARG System quiet
  190. Call TIME('R')
  191.  
  192. If system = "" then DO
  193.  call fuckwit
  194.  EXIT
  195.  END
  196.  
  197. If ~ EXISTS(Config) then DO
  198.  say 'And WHERE, pray tell, is the CONFIG? Hmmmm?!'
  199.  EXIT
  200.  END
  201.  
  202. If strip(quiet) = 'QUIET' then do
  203.  Quiet = 0
  204.  nil = '>NIL: '
  205.  end
  206. Else Do
  207.  Quiet = 1
  208.  nil = ''
  209.  end
  210.  
  211. If quiet = 1 then DO
  212.  say ''
  213.  say '*** Welcome to Packet Shovel 1.1 by Mat Bettinson. ***'
  214.  say ''
  215.  END
  216.  
  217. call Readconfig
  218.  
  219. n = 1
  220.  
  221. Do i = 1 to numshove
  222.  NetMtemp = Flowsrce.i||Flowaddr.i
  223.  If exists(NetMtemp'.DUT') then DO
  224.   NetmailFile = netMtemp'.DUT'
  225.   call CopyNetMail
  226.   END
  227.  If exists(NetMtemp'.HUT') then DO
  228.   NetmailFile = netMtemp'.HUT'
  229.   call CopyNetMail
  230.   END
  231.  If exists(NetMtemp'.CUT') then DO
  232.   NetmailFile = netMtemp'.CUT'
  233.   call CopyNetMail
  234.   END
  235.  If exists(NetMtemp'.OUT') then DO
  236.   NetmailFile = netMtemp'.OUT'
  237.   call CopyNetMail
  238.   END
  239.  
  240.  FlowDest = Flowdest.i
  241.  
  242.  If exists(NetMtemp'.FLO') then DO
  243.   Flowfile = NetMtemp'.FLO'
  244.   Call FlowfileExtract
  245.   END
  246.  If exists(NetMtemp'.HLO') then DO
  247.   Flowfile = NetMtemp'.HLO'
  248.   Call FlowfileExtract
  249.   END
  250.  If exists(NetMtemp'.CLO') then DO
  251.   Flowfile = NetMtemp'.CLO'
  252.   Call FlowfileExtract
  253.   END
  254.  END
  255.  
  256. address COMMAND
  257. DosCOM
  258.  
  259. say ''
  260. say 'Packet Shovel 1.1 finished.'
  261. say ''
  262. EXIT
  263.  
  264. (* Input: Flowfile and FlowDest. *) 
  265.  
  266. FlowfileExtract:
  267.  
  268. Call Open(Flow,Flowfile,'R')
  269.  
  270. Do until EOF(flow)
  271.  Flowline = READLN(Flow)
  272.  If Length(flowline) < 3 then break
  273.  Flowline = translate(flowline,'^','#')
  274.  If left(flowline,1) = '^' then DO
  275.   flowline = Delstr(strip(flowline),1,1)
  276.   Delete = 'YES'
  277.   END
  278.  ELSE delete = 'NO'
  279.  Address COMMAND
  280.  testfile = flowline
  281.  Call getfiletype
  282.  If testfile = 'PKT' then DO
  283.   mailtype = 2
  284.   FileEXT = right(flowline,4)
  285.   call datestamp
  286.   Address COMMAND
  287.   EXEdir'Copy 'flowline' to 'Flowdest||stamp
  288.   If quiet = 1 then say 'Copying 'flowline' to 'flowdest' as 'stamp 
  289.   END
  290.  If testfile = 'BIN' then DO
  291.   Address COMMAND
  292.   EXEdir'Copy 'flowline' to 'Flowdest
  293.   If quiet = 1 then say 'Copying 'flowline' to 'flowdest
  294.   END
  295.  If delete = 'YES' then DO
  296.   Address COMMAND
  297.   EXEdir'Delete 'niL||flowline
  298.   END
  299.  END
  300. eh = Close(flow)
  301. address COMMAND
  302. EXEdir'delete 'NIL||flowfile
  303. RETURN
  304.  
  305. (* Routine that scans the config file and parses the commands one by one
  306.   and executes instructions relevant to that command. System copies are 
  307.   logged in an array and the total number of network addresses to be 
  308.   copied is returned in numshove which is used as the upper limit for the 
  309.   do (for next loop) loop which runs through checking for Netmail 
  310.   packets and flow files... 
  311. *)
  312.  
  313. ReadConfig:
  314.  
  315. Call Open(CFG,Config,"R")
  316.  
  317. Do UNTIL EOF(CFG)
  318.  Do UNTIL EOF(CFG)
  319.   raw = ReadLN(CFG)
  320.   Parse UPPER VAR raw command readsys
  321.   If command = 'SYSTEM' then break
  322.   END
  323.   readsys = strip(readsys)
  324.   IF readsys = system then break
  325.  END
  326.  
  327. If readsys ~= system then DO
  328.  Say 'System not FOUND!!!'
  329.  EXIT
  330.  END
  331.  
  332. Numshove = 0
  333.  
  334. Flowsrce = 0
  335. Flowdest = 0
  336. FlowAddr = 0
  337.  
  338. DO UNTIL EOF(CFG)
  339.  CFGLine = READLN(CFG)
  340.  Parse UPPER VAR CFGline Command Data1 Data2 Data3
  341.  SELECT
  342.   WHEN Command = 'MOVE' then DO
  343.    Numshove = numshove + 1
  344.    Flowsrce.Numshove = strip(Data1)
  345.    Flowdest.Numshove = strip(Data2)
  346.    FlowAddr.Numshove = translate(strip(Data3),'..',':/')
  347.    END
  348.   WHEN Command = 'DOSCOM' then DO
  349.    DOSCom = Data1||data2||data3
  350.    END
  351.   WHEN Command = 'SYSTEM' then DO
  352.    fini = 1
  353.    END
  354.   OTHERWISE nop
  355.   END
  356.  If fini = 1 then break
  357.  END
  358.  
  359. Call Close('CFG')
  360.  
  361. RETURN
  362.  
  363. (* Input Testfile. Output testfile = 'PKT' or 'BIN' *)
  364.  
  365. getfiletype:
  366.  
  367. temp = translate(testfile,' ',':/')
  368. temp = word(temp,words(temp))
  369. temp = delstr(temp,length(temp)-2,2)
  370. temp = compress(temp,'.')
  371. If datatype(temp) = 'NUM' then DO
  372.   testfile = 'PKT'
  373.   END
  374. ELSE testfile = 'BIN'
  375. RETURN
  376.  
  377. (* stamp returns 8 digit hex number with .PKT. N is used to make unique.
  378.    mailtype = 1 = netmail .PKT extension. 0 = echomail .TH3 etc... stripped
  379.    off filename to be really flash. :-) 
  380.  *)
  381.  
  382. datestamp:
  383. n = n + 1 
  384. S = d2x((TIME('E') * 100) + n)
  385. D = d2x(time('S'))
  386. Z = d2x(date('I'))
  387. stamp = right(Z||D||S,8)
  388. ExtTod = '.'UPPER(Left(Date('W'),2))'0'
  389. If mailtype = 1 then stamp = stamp'.PKT'
  390. ELSE stamp = stamp||ExtTod
  391. RETURN
  392.  
  393. (* Copies Netmailfile to flowdest renaming to datestamp.PKT *)
  394.  
  395. CopyNetmail:
  396. mailtype = 1
  397. call datestamp
  398. Address COMMAND
  399. EXEdir'Copy 'Netmailfile' TO 'Flowdest.i||stamp
  400. If Quiet = 1 then DO
  401.   say 'Copying 'Netmailfile' to 'Flowdest.i' as 'stamp
  402.   END
  403. EXEdir'Delete 'NIL||Netmailfile
  404. RETURN
  405.  
  406. fuckwit:
  407. say 
  408. say 'PKTShovel 1.1 from the Plot Hatching Factory.'
  409. say "Written my Mat 'Fingers' Bettinson 10-nov-94"
  410. say 
  411. say 'USAGE: [RX] UnpackPKT <SYSTEM> [quiet]'
  412. say
  413. say 'Note: SYSTEM details in 'Config
  414. say
  415. return
  416. */
  417.  
  418.